
// FTech_ListBoxExDlg.h : header file
//

#pragma once

#include "ListBoxEx.h"
#include "afxwin.h"
#include "afxcmn.h"
#include "Serial.h"
#include "myUtil.h"
#include "myDB.h"
#include <vector>
#include "CSelfTestingShow.h"
using namespace std;

// CFTech_ListBoxExDlg dialog
class CFTech_ListBoxExDlg : public CDialogEx
{
// Construction
public:
	CFTech_ListBoxExDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_FTECH_LISTBOXEX_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
public:
	bool isMCUConnected;
	bool isMeterConnected;
	void Process(float deltaT);
	bool loop;
	CSerial myMcuSerial;
	std::vector<TCHAR> mcuResVec;
	CSerial myMeterSerial;
	CString meterResString;
	bool isFastMode;
	int totalSecondCount;
	int workingGroup;
	CString workingName;
	CString testSeqProjectName;

	float onePortMeasure(CString cmd);
	bool tryExecuteOneMcuCmd(int tryCnt, CString cmd, bool isResetCmd);
	float keepMeasureUniStable(int intervalT, int totalCnt);
	void waitUntilGetMeterRes();
	void clearMeterSerialPort();
	void clearMcuSerialPort();
	void waitUntilGetMcuRes();
	int selftestCnt;
	float readMeasureVal();
	void setMeterResMode();
	void setMeterVdcMode();
	void setMeterAdcMode();
	void setMeterRange(int range);
	void setRefreshRateOnce();
	float ohmsRangeTest(CString rawCmd, int range, CString cmd);
	float vadcTest(CString cmd, CString cmdVdc, CString cmdAdc);
	int transRawCmd(CString cmd);
	vector<CString> testResultVec;
	vector<CString> testResultVecForCSV;
	vector<string> testResultVecForCsv_str;
	CString cmdOhms;
	CString cmdVdc;
	CString cmdAdc;
	vector<CString> selfTestCmdVec;
	int ifStopWhenError;
	int ifRevertPort;
	bool isRequestToStop;
	bool isMcuComError;
	bool isMeterComError;
	void enableAllButton();
	void disableAllButton();
	void disableRootButton();
	void updateTestResultForCSV(string p1, string p2, string expectMin,
		string expectMax, string rangeMax, string val, string testResult, string range);	void inportToTable(CString file);
	bool ifFix2SecondBeforeReadMeter;
	myDB* pRecordDB;
	CString curSN;
	CString curTestSetId;
protected:
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:
	void MainLoop();
	virtual BOOL OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult);
	CListBoxEx m_lbTest;
	afx_msg void OnBnClickedBtnadd();
	afx_msg void OnDestroy();
	afx_msg void OnClickedListBox();
	afx_msg void OnBnClickedButton2();
	afx_msg void OnBnClickedMCUPortConnect();
	afx_msg void OnBnClickedButtonDisconMcu();
	afx_msg void OnBnClickedCancel();
	CButton m_MCUConnectButton;
	CButton m_MCUDisConnectButton;
	CButton m_MeterConnectButton;
	CButton m_MeterDisConnectButton;
	afx_msg void OnBnClickedButtonMcuComSet();
	afx_msg void OnBnClickedButtenExecuteAll();
	afx_msg void OnBnClickedButtonMeterComSet();
	afx_msg void OnBnClickedButtonConMeter();
	afx_msg void OnBnClickedButtonDisconMeter();
	afx_msg void OnBnClickedBtndelseq();
	CEdit mMeasureVal;
	afx_msg void OnBnClickedButtonShowMeasure();
	afx_msg void OnBnClickedBtnInportSeqs();
	CButton mAddSeqBtnCtl;
	CButton mDelSeqBtnCtl;
	CButton mImportSeqBtnCtl;
	CButton mOutputSeqBtnCtl;
	CProgressCtrl mProcessPercent;
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	CButton mExecuteSeqBtnCtl;
	CButton mEncryBtnCtl;
	CButton mDeEncryBtnCtl;
	afx_msg void OnBnClickedBtnoutputseq();
	afx_msg void OnBnClickedButtonReport();
	afx_msg void OnBnClickedButtonSelfTest();
	CButton mBtnSelfTest;
	afx_msg void OnBnClickedCheck2();
	CButton mIfStopWhenError;
	CButton mReportBtn;
	CEdit mWorkingName;
	CEdit mWorkingGroup;
	CEdit mEditCurSN;
	CEdit mEditCurProjectName;
	CEdit mTestResult;
	CComboBox mMCUComPort;
	CComboBox mMeterComPort;
	afx_msg void OnLbnSelchangeList1();
	CButton mIfWait2SecondsMore;
	CButton mReverse;
	afx_msg void OnBnClickedButtonEncrip();
	afx_msg void OnBnClickedButtonDeencry();
	afx_msg void OnBnClickedClearseqbutton();
	CButton mClearSeqButCtl;
	CButton mShowMeasureButCtl;
	afx_msg void OnBnClickedButCreateCsvDemo();
	CSelfTestingShow dlgShow;
	bool isSelfTesting;
	bool isUserTerminal;
	CButton mCreateDemoCsvBut;
	bool isComTryTimeOut;
	afx_msg void OnBnClickedUserterminate();
	int interValTime;
	int tryMeasureTimes;
	float stableRange;
};
